package com.exam.Mapper;

import com.exam.Entity.Admin;
import com.exam.Entity.CustomUserDetails;
import com.exam.Entity.Student;
import com.exam.Entity.Teacher;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;

@Mapper
public interface LoginMapper {

    @Select("select id,name,\"0\" as role from admin where id = #{username} and password = #{password}")
    public Admin adminLogin(Integer username, String password);

    @Select("select tno,tname,institute,phoneNumber,email,\"1\" as role" +
            " from teacher where tno = #{username} and password = #{password}")
    public Teacher teacherLogin(Integer username, String password);

    @Select("select sno,sname,gender,phoneNumber,email,major,\"2\" as role" +
            " from student where sno = #{username} and password = #{password}")
    public Student studentLogin(Integer username, String password);

    @Select("SELECT sno, password, sname,true AS enabled FROM student WHERE sno = #{username}")
    CustomUserDetails loadStudentByUsername(String username);

    @Select("SELECT tno, password, tname,true AS enabled FROM teacher WHERE tno = #{username}")
    CustomUserDetails loadTeacherByUsername(String username);

    @Select("SELECT id, password, name,true AS enabled FROM admin WHERE id = #{username}")
    CustomUserDetails loadAdminByUsername(String username);
}
